require("../css/courseInfo.less")

window.onload = function(){
    // 获取标签
    // 渲染的标签
    let videoImg = document.querySelector("header img")
    let name = document.querySelector(".name")
    let calorie = document.querySelector(".calorie")
    let time = document.querySelector(".time")
    let peoplenum = document.querySelector(".peoplenum")
    let desc = document.querySelector(".desc")


    // 事件的标签
    let videoBtn = document.querySelector("header")
    let begin = document.querySelector(".begin")

    // 全局变量
    let baseUrl = "http://139.9.177.51:8099"
    let courseList = ""
    // 拿到课程id
    console.log(location.search);
    let id = tool.searchToObj(location.search)
    // 进入页面,请求课程详情,并渲染到页面
    http.get("/sports/courseDetail",{id:id.id},function(res){
        console.log(res);
        // 渲染到页面
        videoImg.src = baseUrl + res.data.imgurl
        name.textContent = res.data.name
        calorie.textContent = res.data.calorie
        time.textContent = res.data.time
        peoplenum.textContent = res.data.peoplenum
        desc.textContent = res.data.desc
        // 把视频和图片路径赋值给全局变量courseList
        courseList = res.data.fragments
    })
    // 点击跳转课程
    videoBtn.addEventListener("click",function(){
        // 跳转页面之前,把视频和图片路径存储到会话存储
        sessionStorage.setItem("videoList",JSON.stringify(courseList))
        // 跳转页面
        location.href = "course.html"
    })
    begin.addEventListener("click",function(){
        // 跳转页面之前,把视频和图片路径存储到会话存储
        sessionStorage.setItem("courseList",JSON.stringify(courseList))
        // 跳转页面
        location.href = "course.html"
    })

}